package com.GDOU.service.serviceImp;

import com.GDOU.bean.Student;
import com.GDOU.mapper.StudentMapper;
import com.GDOU.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public int addStudent(Student student) {
        student.setStuStatus("正常");
        return studentMapper.addStudent(student);
    }

    @Override
    public int deleteStudent(String stuNum) {
        return studentMapper.deleteStudent(stuNum);
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public List<Student> getAllStudent() {
        return studentMapper.getAllStudent();
    }

    @Override
    public PageInfo<Student> getStudentPage(Integer pageNum) {
        //开启分页功能
        PageHelper.startPage(pageNum,5);
        //查询所有学生信息
        List<Student> studentList = studentMapper.getAllStudent();
        //获取分页数据
        PageInfo<Student>page=new PageInfo<>(studentList,5);
        return page;
    }

    @Override
    public Student getStudentByName(String stuName) {
        return studentMapper.getStudentByName(stuName);
    }
}
